﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Save_Editor.Classes
{
    public class StringToInt :IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(int))
            {
                return (int)value;
            }
            else
            {

            }
            return (int)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(string))
            {
                int r = 0;
                if (!int.TryParse((string)value, out r))
                {
                    return 0;
                }
                else
                    return r;
            }
                return 0;
        }
    }

    public class NBoolToBool:IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new Nullable<bool>((bool)value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return (bool)value;
        }
    }

    public class StringToDouble : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(double))
            {
                return (double)value;
            }
            else
            {

            }
            return (double)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(string))
            {
                double r = 0.0;
                if (!double.TryParse((string)value, out r))
                {
                    return 0.0;
                }
                else
                    return r;
            }
            return 0.0;
        }
    }

    public class StringToFloat : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(float))
            {
                return (float)value;
            }
            else
            {

            }
            return (float)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(string))
            {
                float r = 0;
                if (!float.TryParse((string)value, out r))
                {
                    return 0;
                }
                else
                    return r;
            }
            return 0;
        }
    }
}
